{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alessandro Parisi \n",
      "last updated: 2019-02-18 \n",
      "\n",
      "CPython 3.5.4\n",
      "IPython 6.1.0\n",
      "\n",
      "numpy 1.16.1\n",
      "pandas 0.20.3\n",
      "matplotlib 2.0.2\n",
      "sklearn 0.20.0\n",
      "seaborn 0.8.0\n"
     ]
    }
   ],
   "source": [
    "%load_ext watermark\n",
    "%watermark -a \"Alessandro Parisi\" -u -d -v -p numpy,pandas,matplotlib,sklearn,seaborn\n",
    "# to install watermark launch 'pip install watermark' at command line"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Execute plot() inline without calling show()\n",
    "%matplotlib inline\n",
    "import warnings\n",
    "warnings.simplefilter('ignore')\n",
    "\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "\n",
    "df = pd.read_csv('../datasets/sms_spam_perceptron.csv')\n",
    "\n",
    "y = df.iloc[:, 0].values\n",
    "y = np.where(y == 'spam', -1, 1)\n",
    "\n",
    "X = df.iloc[:, [1, 2]].values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from sklearn.model_selection import train_test_split\n",
    "\n",
    "X_train, X_test, y_train, y_test = train_test_split(\n",
    "         X, y, test_size=0.3, random_state=0)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Perceptron(alpha=0.0001, class_weight=None, early_stopping=False, eta0=0.1,\n",
       "      fit_intercept=True, max_iter=40, n_iter=None, n_iter_no_change=5,\n",
       "      n_jobs=None, penalty=None, random_state=0, shuffle=True, tol=None,\n",
       "      validation_fraction=0.1, verbose=0, warm_start=False)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.linear_model import Perceptron\n",
    "\n",
    "p = Perceptron(max_iter=40, eta0=0.1, random_state=0)\n",
    "p.fit(X_train, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "y_pred = p.predict(X_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAagAAAEYCAYAAAAJeGK1AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xt8VPWd//HXRwSiTSIVCJZLNCrblirFclOjo7QUqdpt\ntWsFH7i2TReo1GqpvQz6W7W1RH/tZm1Ri1nDr/qrxS6/grUVb/wWRVPlEoviHQtUvAbtAhMRFPzs\nH3MGhpDLmMzMOZN5Px+PeWRmMjnz5oh5c873O99j7o6IiEjUHBR2ABERkbaooEREJJJUUCIiEkkq\nKBERiSQVlIiIRJIKSkREIkkFJSIikaSCEhGRSFJBiYhIJB0cdoAPo7R0gPfvf1TYMSLljVf3cARv\nMHBIn7CjiIhkpOnll99y94Gdva6gCqp//6O44oo1YceIlIYGaF77Km+/uoeNo8+DmpqwI4mIdMhm\nzPhbJq/TKb4CV1MD8XlDoKRv2FFERLJKBSUiIpGkgupBxq+dDytWhB1DRCQrCmoMStoXrxtE7ZxD\nGL/oe6xcP1NjUSJ58P7BB/PK0Uez89BDw44SSSU7djB0wwZ6797dpZ9XQfUg1ZPLWX9fadgxRIrG\nK0cfTdmwYRxVVoaZhR0nUtydtxMJXgGqXnyxS9vQKT4RkS7aeeih9Fc5tcnM6F9W1q2jSxVUD9O8\ns5yqpkVQWxt2FJGioHJqX3f3jQqqB4nFkmNRDKtk/GuLNWFCRAqaCqoHqq4GevcOO4aI5NHz69dz\n0he+QN+hQ/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pyDsZvsdZwE0k98dqjVlJmFRQUvSCRXx3uPtvgJ+R/OUMsAkYHdz/Strr\nj3H3de5+PcnSSBXUOEuurH4QcD7wKPA4UG1mxwY/+xEz+wfgBeBjZjY2eL4sKIMEyUt6HyC4avBm\n4DzgMZJHVJez7xItj5Acv+plZgNJHm2tamNTK4Avm9khllxR/4tBhoOAYe6+HPghcBhQ2ukOFMkR\nFZQIHA+sCk7BXQVcGzx/DfALM1sD7El7/WXBRISngPeBe4PnVwM3krwc90aSp9G2AF8DFgavfwz4\nRFA25wPzzOxJ4EGSR2nLgRFtTZIIPAI0u/u7wf2hwVeAJSRP0T0J/BfwA3d/o/UGgkuH/y543b1B\nbkiuCP8bM1tH8ujsl+6+tdO9J5IjWs1cJAvM7HTgcnc/O+wsIj2FjqBERCSSdAQlIiKRpCMoERGJ\nJBWUiIhEkgpKREQiSQUlIiKRpIISEZFI+h8epD8JU53/8wAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xa2869b64e0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Thanks to Sebastian Raschka for 'plot_decision_regions'\n",
    "# https://github.com/rasbt/python-machine-learning-book\n",
    "from defs import plot_decision_regions\n",
    "\n",
    "X_combined = np.vstack((X_train, X_test))\n",
    "y_combined = np.hstack((y_train, y_test))\n",
    "\n",
    "plot_decision_regions(X=X_combined, y=y_combined,\n",
    "                      classifier=p, test_idx=range(-5, 5))\n",
    "plt.xlabel('suspect words')\n",
    "plt.ylabel('spam or ham')\n",
    "plt.legend(loc='upper right')\n",
    "\n",
    "plt.tight_layout()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Misclassified samples: 3\n",
      "Accuracy: 0.90\n"
     ]
    }
   ],
   "source": [
    "from sklearn.metrics import accuracy_score\n",
    "\n",
    "print('Misclassified samples: %d' % (y_test != y_pred).sum())\n",
    "print('Accuracy: %.2f' % accuracy_score(y_test, y_pred))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Py35",
   "language": "python",
   "name": "py35"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
